

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=auto>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/fluid.png">
  <link rel="icon" href="/img/fluid.png">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="author" content="XiaoMaDing">
  <meta name="keywords" content="">
  
    <meta name="description" content="背景以前项目中遇到需要发送消息触发提醒时，都是直接调用消息中心、三方消息渠道的API，进行业务消息推送 但是最近开发的几个需求，都要求对不同角色、不同消息渠道，进行消息触达推送。如果继续采用之前的方式，会造成相似功能重复开发，且难以维护。           迭代改进：基于上述背景，决定使用设计模式进行抽象，使其达到可复用、可扩展、配置化。 期望达成效果：后续有类似需求时，只需开发少量代码(策略扩">
<meta property="og:type" content="article">
<meta property="og:title" content="项目实战：策略与责任链模式在项目中的应用">
<meta property="og:url" content="http://example.com/2023/02/08/%E9%A1%B9%E7%9B%AE%E5%AE%9E%E6%88%98%EF%BC%9A%E7%AD%96%E7%95%A5%E4%B8%8E%E8%B4%A3%E4%BB%BB%E9%93%BE%E6%A8%A1%E5%BC%8F%E5%9C%A8%E9%A1%B9%E7%9B%AE%E4%B8%AD%E7%9A%84%E5%BA%94%E7%94%A8/index.html">
<meta property="og:site_name" content="剑出">
<meta property="og:description" content="背景以前项目中遇到需要发送消息触发提醒时，都是直接调用消息中心、三方消息渠道的API，进行业务消息推送 但是最近开发的几个需求，都要求对不同角色、不同消息渠道，进行消息触达推送。如果继续采用之前的方式，会造成相似功能重复开发，且难以维护。           迭代改进：基于上述背景，决定使用设计模式进行抽象，使其达到可复用、可扩展、配置化。 期望达成效果：后续有类似需求时，只需开发少量代码(策略扩">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="http://example.com/index_img/design.png">
<meta property="article:published_time" content="2023-02-08T04:46:20.000Z">
<meta property="article:modified_time" content="2023-09-25T13:52:59.334Z">
<meta property="article:author" content="XiaoMaDing">
<meta property="article:tag" content="设计模式">
<meta property="article:tag" content="策略模式">
<meta property="article:tag" content="责任链模式">
<meta property="article:tag" content="消息发送">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:image" content="http://example.com/index_img/design.png">
  
  
    <meta name="referrer" content="no-referrer-when-downgrade">
  
  
  <title>项目实战：策略与责任链模式在项目中的应用 - 剑出</title>

  <link  rel="stylesheet" href="https://lib.baomitu.com/twitter-bootstrap/4.6.1/css/bootstrap.min.css" />



  <link  rel="stylesheet" href="https://lib.baomitu.com/github-markdown-css/4.0.0/github-markdown.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/hint.css/2.7.0/hint.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/prism/1.29.0/plugins/line-numbers/prism-line-numbers.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.css" />



<!-- 主题依赖的图标库，不要自行修改 -->
<!-- Do not modify the link that theme dependent icons -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_hj8rtnfg7um.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_lbnruvf0jn.css">


<link  rel="stylesheet" href="/css/main.css" />


  <link id="highlight-css" rel="stylesheet" href="/css/highlight.css" />
  
    <link id="highlight-css-dark" rel="stylesheet" href="/css/highlight-dark.css" />
  




  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    Fluid.ctx = Object.assign({}, Fluid.ctx)
    var CONFIG = {"hostname":"example.com","root":"/","version":"1.9.5-a","typing":{"enable":true,"typeSpeed":40,"cursorChar":"_","loop":false,"scope":[]},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"left","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"code_language":{"enable":true,"default":"TEXT"},"copy_btn":true,"image_caption":{"enable":true},"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"placement":"left","headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":4},"lazyload":{"enable":true,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":true,"follow_dnt":false,"baidu":"e0dcc0c9ab8f117bb83579322e04efb8","google":null,"gtag":null,"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null,"path":"window.location.pathname","ignore_local":false}},"search_path":"/local-search.xml","include_content_in_search":true};

    if (CONFIG.web_analytics.follow_dnt) {
      var dntVal = navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack;
      Fluid.ctx.dnt = dntVal && (dntVal.startsWith('1') || dntVal.startsWith('yes') || dntVal.startsWith('on'));
    }
  </script>
  <script  src="/js/utils.js" ></script>
  <script  src="/js/color-schema.js" ></script>
  

  
    <!-- Baidu Analytics -->
    <script async>
      if (!Fluid.ctx.dnt) {
        var _hmt = _hmt || [];
        (function() {
          var hm = document.createElement("script");
          hm.src = "https://hm.baidu.com/hm.js?e0dcc0c9ab8f117bb83579322e04efb8";
          var s = document.getElementsByTagName("script")[0];
          s.parentNode.insertBefore(hm, s);
        })();
      }
    </script>
  

  

  

  

  

  



  
<meta name="generator" content="Hexo 6.3.0"></head>


<body>
  

  <header>
    

<div class="header-inner" style="height: 60vh;">
  <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/">
      <strong>剑出</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                <span>首页</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                <span>归档</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                <i class="iconfont icon-category-fill"></i>
                <span>分类</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/">
                <i class="iconfont icon-tags-fill"></i>
                <span>标签</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                <span>关于</span>
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              <i class="iconfont icon-search"></i>
            </a>
          </li>
          
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">
              <i class="iconfont icon-dark" id="color-toggle-icon"></i>
            </a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

  

<div id="banner" class="banner" parallax=true
     style="background: url('/img/yuzhou.gif') no-repeat center center; background-size: cover;">
  <div class="full-bg-img">
    <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
      <div class="banner-text text-center fade-in-up">
        <div class="h2">
          
            <span id="subtitle" data-typed-text="项目实战：策略与责任链模式在项目中的应用"></span>
          
        </div>

        
          
  <div class="mt-3">
    
    
      <span class="post-meta">
        <i class="iconfont icon-date-fill" aria-hidden="true"></i>
        <time datetime="2023-02-08 12:46" pubdate>
          2023年2月8日 下午
        </time>
      </span>
    
  </div>

  <div class="mt-1">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-chart"></i>
        
          8.8k 字
        
      </span>
    

    
      <span class="post-meta mr-2">
        <i class="iconfont icon-clock-fill"></i>
        
        
        
          74 分钟
        
      </span>
    

    
    
      
        <span id="busuanzi_container_page_pv" style="display: none">
          <i class="iconfont icon-eye" aria-hidden="true"></i>
          <span id="busuanzi_value_page_pv"></span> 次
        </span>
        
      
    
  </div>


        
      </div>

      
    </div>
  </div>
</div>

</div>

  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="side-col d-none d-lg-block col-lg-2">
      
  <aside class="sidebar" style="padding-left: 2rem; margin-right: -1rem">
    <div id="toc">
  <p class="toc-header">
    <i class="iconfont icon-list"></i>
    <span>目录</span>
  </p>
  <div class="toc-body" id="toc-body"></div>
</div>



  </aside>


    </div>

    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div id="board">
          <article class="post-content mx-auto">
            <h1 id="seo-header">项目实战：策略与责任链模式在项目中的应用</h1>
            
              <p class="note note-info">
                
                  
                    本文最后更新于：10 个月前
                  
                
              </p>
            
            
              <div class="markdown-body">
                
                <h1 id="背景"><a href="#背景" class="headerlink" title="背景"></a>背景</h1><p>以前项目中遇到需要发送消息触发提醒时，都是直接调用消息中心、三方消息渠道的API，进行业务消息推送</p>
<p>但是最近开发的几个需求，都要求对不同角色、不同消息渠道，进行消息触达推送。如果继续采用之前的方式，会造成相似功能重复开发，且难以维护。</p>
<img src="/2023/02/08/%E9%A1%B9%E7%9B%AE%E5%AE%9E%E6%88%98%EF%BC%9A%E7%AD%96%E7%95%A5%E4%B8%8E%E8%B4%A3%E4%BB%BB%E9%93%BE%E6%A8%A1%E5%BC%8F%E5%9C%A8%E9%A1%B9%E7%9B%AE%E4%B8%AD%E7%9A%84%E5%BA%94%E7%94%A8/image-20230608161258537.png" srcset="/img/loading.gif" lazyload alt="image-20230608161258537" style="zoom:80%;">  

<p><b><br></b></p>
<img src="/2023/02/08/%E9%A1%B9%E7%9B%AE%E5%AE%9E%E6%88%98%EF%BC%9A%E7%AD%96%E7%95%A5%E4%B8%8E%E8%B4%A3%E4%BB%BB%E9%93%BE%E6%A8%A1%E5%BC%8F%E5%9C%A8%E9%A1%B9%E7%9B%AE%E4%B8%AD%E7%9A%84%E5%BA%94%E7%94%A8/image-20230608161143052.png" srcset="/img/loading.gif" lazyload alt="image-20230608161143052" style="zoom:80%;"> 



<h1 id="迭代"><a href="#迭代" class="headerlink" title="迭代"></a>迭代</h1><p>改进：基于上述背景，决定使用设计模式进行抽象，使其达到可复用、可扩展、配置化。</p>
<p>期望达成效果：后续有类似需求时，只需开发少量代码(<code>策略扩展、消息内容组装</code>) + 配置，即可实现功能</p>
<br>



<h2 id="演示"><a href="#演示" class="headerlink" title="演示"></a>演示</h2><p>以【消费者收货】这个业务场景为例，看一下项目中的效果：</p>
<p>□ Nacos配置：</p>
<figure><div class="code-wrapper"><pre class="line-numbers language-properties" data-language="properties"><code class="language-properties"><span class="token key attr-name">msg-push</span><span class="token punctuation">:</span>
<span class="token key attr-name">    msgConfig</span><span class="token punctuation">:</span>
<span class="token key attr-name">      "CONFIRM_RECEIPT_V2"</span><span class="token punctuation">:</span>     
<span class="token key attr-name">        "WX_CP"</span><span class="token punctuation">:</span> 
<span class="token key attr-name">          template</span><span class="token punctuation">:</span> <span class="token value attr-value">"您已完成本次扫码收货，获得奖励共计：%s元；金额已发放至您的电子钱包"</span>
<span class="token key attr-name">        "WX_MP"</span><span class="token punctuation">:</span>
<span class="token key attr-name">          template</span><span class="token punctuation">:</span> <span class="token value attr-value">"fKpHLE8jS18NdRczF8iJBS1HPNazDi9XUd-dY34bpzU"  </span>
<span class="token key attr-name">        "WX_APP"</span><span class="token punctuation">:</span>
<span class="token key attr-name">          template</span><span class="token punctuation">:</span> <span class="token value attr-value">"NpPdb5ghfEZnoG0AHg8zthOWu0oHIx0QIdzS1m1LPVo"      </span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre></div></figure>

<br>

<p>□ 效果：在各个终端上，就会收到消息通知</p>
<figure><div class="code-wrapper"><pre class="line-numbers language-bash" data-language="bash"><code class="language-bash">xx.RebateSmsMsgStrategy   - <span class="token punctuation">[</span>消息V2<span class="token punctuation">]</span>发送短信,msgType：CONFIRM_RECEIPT_V2,msgSendReq：
xx.RebateWxCpMsgStrategy  - <span class="token punctuation">[</span>消息V2<span class="token punctuation">]</span>发送企微文本消息,msgType：CONFIRM_RECEIPT_V2,msgSendReq：
xx.RebateWxMpMsgStrategy  - <span class="token punctuation">[</span>消息V2<span class="token punctuation">]</span>发送微信公众号消息,msgType：CONFIRM_RECEIPT_V2,msgSendReq：
xx.RebateWxAppMsgStrategy - <span class="token punctuation">[</span>消息V2<span class="token punctuation">]</span>发送微信小程序消息,msgType：CONFIRM_RECEIPT_V2,msgSendReq：<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span></span></code></pre></div></figure>





<h2 id="设计"><a href="#设计" class="headerlink" title="设计"></a>设计</h2><p>□ 整体流程：</p>
<img src="/2023/02/08/%E9%A1%B9%E7%9B%AE%E5%AE%9E%E6%88%98%EF%BC%9A%E7%AD%96%E7%95%A5%E4%B8%8E%E8%B4%A3%E4%BB%BB%E9%93%BE%E6%A8%A1%E5%BC%8F%E5%9C%A8%E9%A1%B9%E7%9B%AE%E4%B8%AD%E7%9A%84%E5%BA%94%E7%94%A8/image-20230608143511193.png" srcset="/img/loading.gif" lazyload alt="image-20230608143511193" style="zoom:80%;"> 

<br>

<br>

<p>□ 类设计：责任链模式 + 策略模式</p>
<img src="/2023/02/08/%E9%A1%B9%E7%9B%AE%E5%AE%9E%E6%88%98%EF%BC%9A%E7%AD%96%E7%95%A5%E4%B8%8E%E8%B4%A3%E4%BB%BB%E9%93%BE%E6%A8%A1%E5%BC%8F%E5%9C%A8%E9%A1%B9%E7%9B%AE%E4%B8%AD%E7%9A%84%E5%BA%94%E7%94%A8/image-20230608124549023.png" srcset="/img/loading.gif" lazyload alt="image-20230608124549023" style="zoom:80%;"> 



<br>

<br>

<p>□ 配置设计：</p>
<figure><div class="code-wrapper"><pre class="line-numbers language-properties" data-language="properties"><code class="language-properties"><span class="token key attr-name">msg-push</span><span class="token punctuation">:</span>
<span class="token key attr-name">    msgConfig</span><span class="token punctuation">:</span>
<span class="token key attr-name">      "CONFIRM_RECEIPT_V2"</span><span class="token punctuation">:</span>
<span class="token key attr-name">        "WX_CP"</span><span class="token punctuation">:</span> 
<span class="token key attr-name">          template</span><span class="token punctuation">:</span> <span class="token value attr-value">"您已完成本次扫码收货，获得奖励共计：%s元；金额已发放至您的电子钱包"</span>
<span class="token key attr-name">        "WX_MP"</span><span class="token punctuation">:</span>
<span class="token key attr-name">          template</span><span class="token punctuation">:</span> <span class="token value attr-value">"fKpHLE8jS18NdRczF8iJBS1HPNazDi9XUd-dY34bpzU"  </span>
<span class="token key attr-name">        "WX_APP"</span><span class="token punctuation">:</span>
<span class="token key attr-name">          template</span><span class="token punctuation">:</span> <span class="token value attr-value">"NpPdb5ghfEZnoG0AHg8zthOWu0oHIx0QIdzS1m1LPVo"     </span>
<span class="token key attr-name">        "SMS"</span><span class="token punctuation">:</span>
<span class="token key attr-name">          template</span><span class="token punctuation">:</span> <span class="token value attr-value">"SMS_267100068"  </span>
<span class="token key attr-name">      "其他发送消息的业务场景"</span><span class="token punctuation">:</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre></div></figure>



<h1 id="代码实现"><a href="#代码实现" class="headerlink" title="代码实现"></a>代码实现</h1><p>整体类结构：</p>
<img src="/2023/02/08/%E9%A1%B9%E7%9B%AE%E5%AE%9E%E6%88%98%EF%BC%9A%E7%AD%96%E7%95%A5%E4%B8%8E%E8%B4%A3%E4%BB%BB%E9%93%BE%E6%A8%A1%E5%BC%8F%E5%9C%A8%E9%A1%B9%E7%9B%AE%E4%B8%AD%E7%9A%84%E5%BA%94%E7%94%A8/image-20230608153923272.png" srcset="/img/loading.gif" lazyload alt="image-20230608153923272" style="zoom:67%;"> 





<h2 id="配置"><a href="#配置" class="headerlink" title="配置"></a>配置</h2><ol>
<li><p>消息推送配置类：</p>
<figure><div class="code-wrapper"><pre class="line-numbers language-java" data-language="java"><code class="language-java"><span class="token annotation punctuation">@Data</span>
<span class="token annotation punctuation">@ConfigurationProperties</span><span class="token punctuation">(</span>prefix <span class="token operator">=</span> <span class="token string">"msg-push"</span><span class="token punctuation">)</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">RebateMsgProperties</span> <span class="token punctuation">&#123;</span>

    <span class="token comment">/**
     * 消息推送配置
     * key：消息业务场景，BizMsgTypeEnum
     * value：消息推送渠道，MsgPushChannelEnum
     */</span>
    <span class="token keyword">private</span> <span class="token class-name">Map</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">,</span> <span class="token class-name">Map</span><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">,</span> <span class="token class-name">MsgConfig</span><span class="token punctuation">></span><span class="token punctuation">></span></span> msgConfig <span class="token operator">=</span> <span class="token class-name">Maps</span><span class="token punctuation">.</span><span class="token function">newHashMap</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token annotation punctuation">@Data</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">class</span> <span class="token class-name">MsgConfig</span> <span class="token punctuation">&#123;</span>
        <span class="token comment">/**
         * 模板
         */</span>
        <span class="token keyword">private</span> <span class="token class-name">String</span> template<span class="token punctuation">;</span>
        
        <span class="token comment">/**
         * 如果是企微机器人这类的，需指定发送到哪里，一般是个固定的配置
         */</span>
        <span class="token keyword">private</span> <span class="token class-name">String</span> <span class="token keyword">to</span><span class="token punctuation">;</span>
    <span class="token punctuation">&#125;</span>
<span class="token punctuation">&#125;</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre></div></figure>

<img src="/2023/02/08/%E9%A1%B9%E7%9B%AE%E5%AE%9E%E6%88%98%EF%BC%9A%E7%AD%96%E7%95%A5%E4%B8%8E%E8%B4%A3%E4%BB%BB%E9%93%BE%E6%A8%A1%E5%BC%8F%E5%9C%A8%E9%A1%B9%E7%9B%AE%E4%B8%AD%E7%9A%84%E5%BA%94%E7%94%A8/image-20230608152018621.png" srcset="/img/loading.gif" lazyload alt="image-20230608152018621" style="zoom: 67%;"> 

<img src="/2023/02/08/%E9%A1%B9%E7%9B%AE%E5%AE%9E%E6%88%98%EF%BC%9A%E7%AD%96%E7%95%A5%E4%B8%8E%E8%B4%A3%E4%BB%BB%E9%93%BE%E6%A8%A1%E5%BC%8F%E5%9C%A8%E9%A1%B9%E7%9B%AE%E4%B8%AD%E7%9A%84%E5%BA%94%E7%94%A8/image-20230608152116463.png" srcset="/img/loading.gif" lazyload alt="image-20230608152116463" style="zoom:67%;"> 
</li>
<li><p>消息业务场景枚举：</p>
<figure><div class="code-wrapper"><pre class="line-numbers language-java" data-language="java"><code class="language-java"><span class="token comment">/**
 * 消息业务场景枚举
 */</span>
<span class="token annotation punctuation">@Getter</span>
<span class="token annotation punctuation">@AllArgsConstructor</span>
<span class="token keyword">public</span> <span class="token keyword">enum</span> <span class="token class-name">RebateMsgTypeEnum</span> <span class="token punctuation">&#123;</span>

    <span class="token function">CONFIRM_RECEIPT_V2</span><span class="token punctuation">(</span><span class="token string">"确认收货消息提醒"</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
    <span class="token function">SCAN_SALE_V2</span><span class="token punctuation">(</span><span class="token string">"动销消息提醒"</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
    <span class="token function">RECONCILIATION_HINT</span><span class="token punctuation">(</span><span class="token string">"账单对账提示消息"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    
    <span class="token keyword">private</span> <span class="token class-name">String</span> desc<span class="token punctuation">;</span>
<span class="token punctuation">&#125;</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre></div></figure>
</li>
<li><p>消息推送渠道枚举：</p>
<figure><div class="code-wrapper"><pre class="line-numbers language-java" data-language="java"><code class="language-java"><span class="token comment">/**
 * 消息推送渠道枚举
 */</span>
<span class="token annotation punctuation">@Getter</span>
<span class="token annotation punctuation">@AllArgsConstructor</span>
<span class="token keyword">public</span> <span class="token keyword">enum</span> <span class="token class-name">MsgPushChannelEnum</span> <span class="token punctuation">&#123;</span>

    <span class="token function">WX_CP</span><span class="token punctuation">(</span><span class="token string">"企业微信"</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
    <span class="token function">WX_CP_ROBOT</span><span class="token punctuation">(</span><span class="token string">"企业微信机器人"</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
    <span class="token function">WX_MP</span><span class="token punctuation">(</span><span class="token string">"微信公众号"</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
    <span class="token function">WX_APP</span><span class="token punctuation">(</span><span class="token string">"微信小程序"</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
    <span class="token function">SMS</span><span class="token punctuation">(</span><span class="token string">"短信"</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
    <span class="token function">TAN_HOME</span><span class="token punctuation">(</span><span class="token string">"站内信"</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
    <span class="token punctuation">;</span>

    <span class="token keyword">private</span> <span class="token class-name">String</span> desc<span class="token punctuation">;</span>
<span class="token punctuation">&#125;</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre></div></figure></li>
</ol>
<h2 id="职责链"><a href="#职责链" class="headerlink" title="职责链"></a>职责链</h2><figure><div class="code-wrapper"><pre class="line-numbers language-java" data-language="java"><code class="language-java"><span class="token comment">/**
 * 消息处理责任链
 */</span>
<span class="token annotation punctuation">@Slf4j</span>
<span class="token annotation punctuation">@Service</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">RebateMsgHandlerChain</span> <span class="token punctuation">&#123;</span>

    <span class="token comment">// 注入所有消息策略实现类</span>
    <span class="token annotation punctuation">@Autowired</span>
    <span class="token keyword">private</span> <span class="token class-name">RebateMsgStrategy</span><span class="token punctuation">[</span><span class="token punctuation">]</span> rebateMsgServices<span class="token punctuation">;</span>

    <span class="token comment">/**
     * 遍历所有消息策略，根据配置判断具体消息策略是否支持，调用策略发送消息
     *
     * @param msgType
     * @param customMsgSendReqDto
     */</span>    
    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">sendRebateMsg</span><span class="token punctuation">(</span><span class="token class-name">RebateMsgTypeEnum</span> msgType<span class="token punctuation">,</span> <span class="token class-name">CustomMsgSendReqDto</span> customMsgSendReqDto<span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
        <span class="token keyword">for</span> <span class="token punctuation">(</span><span class="token class-name">RebateMsgStrategy</span> rebateMsgStrategy <span class="token operator">:</span> rebateMsgServices<span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
            <span class="token keyword">if</span> <span class="token punctuation">(</span>rebateMsgStrategy<span class="token punctuation">.</span><span class="token function">support</span><span class="token punctuation">(</span>msgType<span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
                rebateMsgStrategy<span class="token punctuation">.</span><span class="token function">sendRebateMsg</span><span class="token punctuation">(</span>msgType<span class="token punctuation">,</span> customMsgSendReqDto<span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token punctuation">&#125;</span>
        <span class="token punctuation">&#125;</span>
    <span class="token punctuation">&#125;</span>
<span class="token punctuation">&#125;</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre></div></figure>





<h2 id="策略"><a href="#策略" class="headerlink" title="策略"></a>策略</h2><ol>
<li><p>接口：</p>
<figure><div class="code-wrapper"><pre class="line-numbers language-java" data-language="java"><code class="language-java"><span class="token keyword">public</span> <span class="token keyword">interface</span> <span class="token class-name">RebateMsgStrategy</span> <span class="token punctuation">&#123;</span>

    <span class="token comment">/**
     * 消息类型是否支持
     *
     * @param msgType
     * @return
     */</span>
    <span class="token keyword">boolean</span> <span class="token function">support</span><span class="token punctuation">(</span><span class="token class-name">RebateMsgTypeEnum</span> msgType<span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token comment">/**
     * 发送消息
     *
     * @param msgType
     * @param customMsgSendReqDto
     */</span>
    <span class="token keyword">void</span> <span class="token function">sendRebateMsg</span><span class="token punctuation">(</span><span class="token class-name">RebateMsgTypeEnum</span> msgType<span class="token punctuation">,</span> <span class="token class-name">CustomMsgSendReqDto</span> customMsgSendReqDto<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">&#125;</span>
<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre></div></figure>
</li>
<li><p>抽象实现：</p>
<figure><div class="code-wrapper"><pre class="line-numbers language-java" data-language="java"><code class="language-java"><span class="token annotation punctuation">@Slf4j</span>
<span class="token keyword">public</span> <span class="token keyword">abstract</span> <span class="token keyword">class</span> <span class="token class-name">AbstractRebateMsgStrategy</span> <span class="token keyword">implements</span> <span class="token class-name">RebateMsgStrategy</span> <span class="token punctuation">&#123;</span>
    
    <span class="token annotation punctuation">@Autowired</span>
    <span class="token keyword">private</span> <span class="token class-name">RebateMsgProperties</span> rebateMsgProperties<span class="token punctuation">;</span>
    <span class="token annotation punctuation">@Autowired</span>
    <span class="token keyword">private</span> <span class="token class-name">ThreadPoolExecutor</span> threadPoolExecutor<span class="token punctuation">;</span>

    <span class="token comment">/**
     * 获取消息推送渠道
     * @return
     */</span>
    <span class="token keyword">protected</span> <span class="token keyword">abstract</span> <span class="token class-name">MsgPushChannelEnum</span> <span class="token function">getMsgPushChannelEnum</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    
    <span class="token comment">/**
     * 执行具体的消息发送策略
     * @param msgType
     * @param msgSendReqDto
     */</span>
    <span class="token keyword">protected</span> <span class="token keyword">abstract</span> <span class="token keyword">void</span> <span class="token function">doRebateMsgSend</span><span class="token punctuation">(</span><span class="token class-name">RebateMsgTypeEnum</span> msgType<span class="token punctuation">,</span>
                                            <span class="token class-name">MsgSendReqDto</span> msgSendReqDto<span class="token punctuation">)</span><span class="token punctuation">;</span>
     
    <span class="token comment">/**
     * 消息类型是否支持
     * @param msgType
     */</span>
    <span class="token annotation punctuation">@Override</span>
    <span class="token keyword">public</span> <span class="token keyword">final</span> <span class="token keyword">boolean</span> <span class="token function">support</span><span class="token punctuation">(</span><span class="token class-name">RebateMsgTypeEnum</span> msgType<span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
        <span class="token class-name">Map</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">,</span> <span class="token class-name">RebateMsgProperties<span class="token punctuation">.</span>MsgConfig</span><span class="token punctuation">></span></span> msgConfigMap <span class="token operator">=</span> 
            rebateMsgProperties<span class="token punctuation">.</span><span class="token function">getMsgConfig</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">get</span><span class="token punctuation">(</span>msgType<span class="token punctuation">.</span><span class="token function">name</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token class-name">MapUtils</span><span class="token punctuation">.</span><span class="token function">isEmpty</span><span class="token punctuation">(</span>msgConfigMap<span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
            log<span class="token punctuation">.</span><span class="token function">warn</span><span class="token punctuation">(</span><span class="token string">"[消息V2]该消息类型配置不存在,msgType：&#123;&#125;"</span><span class="token punctuation">,</span> msgType<span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token keyword">return</span> <span class="token boolean">false</span><span class="token punctuation">;</span>
        <span class="token punctuation">&#125;</span>
        <span class="token keyword">if</span> <span class="token punctuation">(</span>msgConfigMap<span class="token punctuation">.</span><span class="token function">containsKey</span><span class="token punctuation">(</span><span class="token function">getMsgPushChannelEnum</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">name</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
            <span class="token keyword">return</span> <span class="token boolean">true</span><span class="token punctuation">;</span>
        <span class="token punctuation">&#125;</span>
        <span class="token keyword">return</span> <span class="token boolean">false</span><span class="token punctuation">;</span>
    <span class="token punctuation">&#125;</span>
    
    <span class="token comment">/**
     * 发送消息
     * @param msgType
     * @param customMsgSendReqDto
     */</span>
    <span class="token annotation punctuation">@Override</span>
    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">sendMsg</span><span class="token punctuation">(</span><span class="token class-name">RebateMsgTypeEnum</span> msgType<span class="token punctuation">,</span> <span class="token class-name">CustomMsgSendReqDto</span> customMsgSendReqDto<span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
        <span class="token comment">// 根据业务场景、消息渠道不同，组装成对象的消息请求</span>
        <span class="token class-name">MsgSendReqDto</span> msgSendReqDto <span class="token operator">=</span> <span class="token function">buildMsgContent</span><span class="token punctuation">(</span>msgType<span class="token punctuation">,</span> customMsgSendReqDto<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token class-name">Objects</span><span class="token punctuation">.</span><span class="token function">isNull</span><span class="token punctuation">(</span>msgSendReqDto<span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
            log<span class="token punctuation">.</span><span class="token function">warn</span><span class="token punctuation">(</span><span class="token string">"[消息V2]buildMsgContent为空,不发送,msgType：&#123;&#125;,msgPushChannel：&#123;&#125;,req：&#123;&#125;"</span><span class="token punctuation">,</span>
                     msgType<span class="token punctuation">,</span> <span class="token function">getMsgPushChannelEnum</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">name</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> 
                     <span class="token constant">JSON</span><span class="token punctuation">.</span><span class="token function">toJSONString</span><span class="token punctuation">(</span>customMsgSendReqDto<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token keyword">return</span><span class="token punctuation">;</span>
        <span class="token punctuation">&#125;</span>
        <span class="token function">doRebateMsgSendAsync</span><span class="token punctuation">(</span>msgType<span class="token punctuation">,</span> msgSendReqDto<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">&#125;</span>    
    
    <span class="token comment">/**
     * 异步执行消息发送
     * @param msgType
     * @param msgSendReqDto
     */</span>
    <span class="token keyword">private</span> <span class="token keyword">void</span> <span class="token function">doRebateMsgSendAsync</span><span class="token punctuation">(</span><span class="token class-name">RebateMsgTypeEnum</span> msgType<span class="token punctuation">,</span> <span class="token class-name">MsgSendReqDto</span> msgSendReqDto<span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
        threadPoolExecutor<span class="token punctuation">.</span><span class="token function">execute</span><span class="token punctuation">(</span><span class="token class-name">RunnableWrapper</span><span class="token punctuation">.</span><span class="token function">of</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">-></span> <span class="token punctuation">&#123;</span>
            <span class="token keyword">try</span> <span class="token punctuation">&#123;</span>
                <span class="token function">doRebateMsgSend</span><span class="token punctuation">(</span>msgType<span class="token punctuation">,</span> msgSendReqDto<span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token punctuation">&#125;</span> <span class="token keyword">catch</span> <span class="token punctuation">(</span><span class="token class-name">Exception</span> e<span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
                log<span class="token punctuation">.</span><span class="token function">warn</span><span class="token punctuation">(</span><span class="token string">"[消息V2]异步发送异常errorMsg；&#123;&#125;,msgType：&#123;&#125;,msgPushChannel：&#123;&#125;"</span><span class="token punctuation">,</span> 
                         e<span class="token punctuation">.</span><span class="token function">getMessage</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> msgType<span class="token punctuation">.</span><span class="token function">name</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token function">getMsgPushChannelEnum</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">name</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> 
                         <span class="token constant">JSON</span><span class="token punctuation">.</span><span class="token function">toJSONString</span><span class="token punctuation">(</span>msgSendReqDto<span class="token punctuation">)</span><span class="token punctuation">,</span> e<span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token punctuation">&#125;</span>
        <span class="token punctuation">&#125;</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">&#125;</span> 
<span class="token punctuation">&#125;</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre></div></figure>
</li>
<li><p>具体策略：</p>
<figure><div class="code-wrapper"><pre class="line-numbers language-java" data-language="java"><code class="language-java"><span class="token comment">/**
 * 发送短信
 */</span>
<span class="token annotation punctuation">@Slf4j</span>
<span class="token annotation punctuation">@Service</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">RebateSmsMsgStrategy</span> <span class="token keyword">extends</span> <span class="token class-name">AbstractRebateMsgStrategy</span> <span class="token punctuation">&#123;</span>
    
    <span class="token annotation punctuation">@Autowired</span>
    <span class="token keyword">private</span> <span class="token class-name">MsgClient</span> msgClient<span class="token punctuation">;</span>

    <span class="token comment">/**
     * 获取消息推送渠道
     */</span>
    <span class="token annotation punctuation">@Override</span>
    <span class="token keyword">protected</span> <span class="token class-name">MsgPushChannelEnum</span> <span class="token function">getMsgPushChannelEnum</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
        <span class="token keyword">return</span> <span class="token class-name">MsgPushChannelEnum</span><span class="token punctuation">.</span><span class="token constant">SMS</span><span class="token punctuation">;</span>
    <span class="token punctuation">&#125;</span>    
    
    <span class="token comment">/**
     * 执行具体的消息发送策略
     * @param msgType
     * @param msgSendReqDto
     */</span>
    <span class="token annotation punctuation">@Override</span>
    <span class="token keyword">protected</span> <span class="token keyword">void</span> <span class="token function">doRebateMsgSend</span><span class="token punctuation">(</span><span class="token class-name">RebateMsgTypeEnum</span> msgType<span class="token punctuation">,</span> <span class="token class-name">MsgSendReqDto</span> msgSendReqDto<span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
        log<span class="token punctuation">.</span><span class="token function">info</span><span class="token punctuation">(</span><span class="token string">"[消息V2]发送短信,msgType：&#123;&#125;,msgSendReqDto：&#123;&#125;"</span><span class="token punctuation">,</span> msgType<span class="token punctuation">.</span><span class="token function">name</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
                 <span class="token constant">JSON</span><span class="token punctuation">.</span><span class="token function">toJSONString</span><span class="token punctuation">(</span>msgSendReqDto<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">SmsMsgContentDto</span> smsDto <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token class-name">SmsMsgContentDto</span><span class="token punctuation">)</span> msgSendReqDto<span class="token punctuation">.</span><span class="token function">getContentDto</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        msgClient<span class="token punctuation">.</span><span class="token function">sendSms</span><span class="token punctuation">(</span>msgSendReqDto<span class="token punctuation">.</span><span class="token function">getTo</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> smsDto<span class="token punctuation">.</span><span class="token function">getTemplateCode</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> smsDto<span class="token punctuation">.</span><span class="token function">getParamMap</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">&#125;</span>
<span class="token punctuation">&#125;</span>
    <span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre></div></figure>

<figure><div class="code-wrapper"><pre class="line-numbers language-java" data-language="java"><code class="language-java"><span class="token comment">/**
 * 发送企微消息
 */</span>
<span class="token annotation punctuation">@Slf4j</span>
<span class="token annotation punctuation">@Service</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">RebateWxCpMsgStrategy</span> <span class="token keyword">extends</span> <span class="token class-name">AbstractRebateMsgStrategy</span> <span class="token punctuation">&#123;</span>

    <span class="token annotation punctuation">@Autowired</span>
    <span class="token keyword">private</span> <span class="token class-name">MsgClient</span> msgClient<span class="token punctuation">;</span>

    <span class="token comment">/**
     * 获取消息推送渠道
     */</span>
    <span class="token annotation punctuation">@Override</span>
    <span class="token keyword">protected</span> <span class="token class-name">MsgPushChannelEnum</span> <span class="token function">getMsgPushChannelEnum</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
        <span class="token keyword">return</span> <span class="token class-name">MsgPushChannelEnum</span><span class="token punctuation">.</span><span class="token constant">WX_CP</span><span class="token punctuation">;</span>
    <span class="token punctuation">&#125;</span>

    <span class="token comment">/**
     * 执行具体的消息发送策略
     *
     * @param msgType
     * @param msgSendReqDto
     */</span>
    <span class="token annotation punctuation">@Override</span>
    <span class="token keyword">protected</span> <span class="token keyword">void</span> <span class="token function">doRebateMsgSend</span><span class="token punctuation">(</span><span class="token class-name">RebateMsgTypeEnum</span> msgType<span class="token punctuation">,</span> <span class="token class-name">MsgSendReqDto</span> msgSendReqDto<span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
        log<span class="token punctuation">.</span><span class="token function">info</span><span class="token punctuation">(</span><span class="token string">"[消息V2]发送企微消息,msgType：&#123;&#125;,msgSendReqDto：&#123;&#125;"</span><span class="token punctuation">,</span> msgType<span class="token punctuation">.</span><span class="token function">name</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> 
                 <span class="token constant">JSON</span><span class="token punctuation">.</span><span class="token function">toJSONString</span><span class="token punctuation">(</span>msgSendReqDto<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">Long</span> <span class="token keyword">to</span> <span class="token operator">=</span> <span class="token class-name">Long</span><span class="token punctuation">.</span><span class="token function">valueOf</span><span class="token punctuation">(</span>msgSendReqDto<span class="token punctuation">.</span><span class="token function">getTo</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        msgClient<span class="token punctuation">.</span><span class="token function">sendWxCpTextByGuid</span><span class="token punctuation">(</span><span class="token keyword">to</span><span class="token punctuation">,</span> <span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token class-name">TextMsgContentDto</span><span class="token punctuation">)</span> msgContent<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">getText</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">&#125;</span>
<span class="token punctuation">&#125;</span>
<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre></div></figure>

<figure><div class="code-wrapper"><pre class="line-numbers language-java" data-language="java"><code class="language-java"><span class="token comment">/**
 * 发送企微机器人消息
 */</span>
<span class="token annotation punctuation">@Slf4j</span>
<span class="token annotation punctuation">@Service</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">RebateWxCpRobotMsgStrategy</span> <span class="token keyword">extends</span> <span class="token class-name">AbstractRebateMsgStrategy</span> <span class="token punctuation">&#123;</span>

    <span class="token comment">/**
     * 获取消息推送渠道
     */</span>
    <span class="token annotation punctuation">@Override</span>
    <span class="token keyword">protected</span> <span class="token class-name">MsgPushChannelEnum</span> <span class="token function">getMsgPushChannelEnum</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
        <span class="token keyword">return</span> <span class="token class-name">MsgPushChannelEnum</span><span class="token punctuation">.</span><span class="token constant">WX_CP_ROBOT</span><span class="token punctuation">;</span>
    <span class="token punctuation">&#125;</span>

    <span class="token comment">/**
     * 执行具体的消息发送策略
     * @param msgType
     * @param msgSendReqDto
     */</span>
    <span class="token annotation punctuation">@Override</span>
    <span class="token keyword">protected</span> <span class="token keyword">void</span> <span class="token function">doRebateMsgSend</span><span class="token punctuation">(</span><span class="token class-name">RebateMsgTypeEnum</span> msgType<span class="token punctuation">,</span> <span class="token class-name">MsgSendReqDto</span> msgSendReqDto<span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
        log<span class="token punctuation">.</span><span class="token function">info</span><span class="token punctuation">(</span><span class="token string">"[消息V2]发送企微机器人消息,msgType：&#123;&#125;,msgSendReqDto：&#123;&#125;"</span><span class="token punctuation">,</span> msgType<span class="token punctuation">.</span><span class="token function">name</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> 
                 <span class="token constant">JSON</span><span class="token punctuation">.</span><span class="token function">toJSONString</span><span class="token punctuation">(</span>msgSendReqDto<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">MsgContentDto</span> msgContent <span class="token operator">=</span> msgSendReqDto<span class="token punctuation">.</span><span class="token function">getContentDto</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">if</span> <span class="token punctuation">(</span>msgContent <span class="token keyword">instanceof</span> <span class="token class-name">TextMsgContentDto</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
            <span class="token class-name">MonitorUtils</span><span class="token punctuation">.</span><span class="token function">qwMonitor</span><span class="token punctuation">(</span>msgSendReqDto<span class="token punctuation">.</span><span class="token function">getTo</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> 
                                   <span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token class-name">TextMsgContentDto</span><span class="token punctuation">)</span> msgContent<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">getText</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token keyword">return</span><span class="token punctuation">;</span>
        <span class="token punctuation">&#125;</span>
    <span class="token punctuation">&#125;</span>
<span class="token punctuation">&#125;</span>
<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre></div></figure>

<figure><div class="code-wrapper"><pre class="line-numbers language-java" data-language="java"><code class="language-java"><span class="token comment">/**
 * 发送微信公众号消息
 */</span>
<span class="token annotation punctuation">@Slf4j</span>
<span class="token annotation punctuation">@Service</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">RebateWxMpMsgStrategy</span> <span class="token keyword">extends</span> <span class="token class-name">AbstractRebateMsgStrategy</span> <span class="token punctuation">&#123;</span>

    <span class="token annotation punctuation">@Autowired</span>
    <span class="token keyword">private</span> <span class="token class-name">MsgCenterClient</span> msgCenterClient<span class="token punctuation">;</span>

    <span class="token comment">/**
     * 获取消息推送渠道
     * @return
     */</span>
    <span class="token annotation punctuation">@Override</span>
    <span class="token keyword">protected</span> <span class="token class-name">MsgPushChannelEnum</span> <span class="token function">getMsgPushChannelEnum</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
        <span class="token keyword">return</span> <span class="token class-name">MsgPushChannelEnum</span><span class="token punctuation">.</span><span class="token constant">WX_MP</span><span class="token punctuation">;</span>
    <span class="token punctuation">&#125;</span>


    <span class="token comment">/**
     * 执行具体的消息发送策略
     * @param msgType
     * @param msgSendReqDto
     */</span>
    <span class="token annotation punctuation">@Override</span>
    <span class="token keyword">protected</span> <span class="token keyword">void</span> <span class="token function">doRebateMsgSend</span><span class="token punctuation">(</span><span class="token class-name">RebateMsgTypeEnum</span> msgType<span class="token punctuation">,</span> <span class="token class-name">MsgSendReqDto</span> msgSendReqDto<span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
        log<span class="token punctuation">.</span><span class="token function">info</span><span class="token punctuation">(</span><span class="token string">"[消息V2]发送微信公众号消息,msgType：&#123;&#125;,msgSendReqDto：&#123;&#125;"</span><span class="token punctuation">,</span> msgType<span class="token punctuation">.</span><span class="token function">name</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> 
                 <span class="token constant">JSON</span><span class="token punctuation">.</span><span class="token function">toJSONString</span><span class="token punctuation">(</span>msgSendReqDto<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">WxMpMsgContentDto</span> wxMpMsgContentDto <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token class-name">WxMpMsgContentDto</span><span class="token punctuation">)</span> msgSendReqDto<span class="token punctuation">.</span><span class="token function">getContentDto</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">MessageReq</span> req <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">MessageReq</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">MessageReq<span class="token punctuation">.</span>MpTemplateMsgReq</span> mpTemplateMsg <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">MessageReq<span class="token punctuation">.</span>MpTemplateMsgReq</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        mpTemplateMsg<span class="token punctuation">.</span><span class="token function">setTemplateId</span><span class="token punctuation">(</span>wxMpMsgContentDto<span class="token punctuation">.</span><span class="token function">getTemplateId</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
                <span class="token punctuation">.</span><span class="token function">setDataByMap</span><span class="token punctuation">(</span>wxMpMsgContentDto<span class="token punctuation">.</span><span class="token function">getParamMap</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
                <span class="token punctuation">.</span><span class="token function">setMiniprogram</span><span class="token punctuation">(</span>wxMpMsgContentDto<span class="token punctuation">.</span><span class="token function">getMiniProgramAppId</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
                                wxMpMsgContentDto<span class="token punctuation">.</span><span class="token function">getUrl</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        req<span class="token punctuation">.</span><span class="token function">setAppid</span><span class="token punctuation">(</span>wxMpMsgContentDto<span class="token punctuation">.</span><span class="token function">getAppId</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
                <span class="token punctuation">.</span><span class="token function">setMessageType</span><span class="token punctuation">(</span><span class="token class-name">MessageCenterTypeEnum</span><span class="token punctuation">.</span><span class="token constant">WECHAT_WP</span><span class="token punctuation">.</span><span class="token function">getType</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
                <span class="token punctuation">.</span><span class="token function">setToUser</span><span class="token punctuation">(</span>msgSendReqDto<span class="token punctuation">.</span><span class="token function">getTo</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
                <span class="token punctuation">.</span><span class="token function">setMpTemplateMsg</span><span class="token punctuation">(</span>mpTemplateMsg<span class="token punctuation">)</span><span class="token punctuation">;</span>
        msgCenterClient<span class="token punctuation">.</span><span class="token function">sendMsg</span><span class="token punctuation">(</span><span class="token function">getMsgPushChannelEnum</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> req<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">&#125;</span>
<span class="token punctuation">&#125;</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre></div></figure>

<figure><div class="code-wrapper"><pre class="line-numbers language-java" data-language="java"><code class="language-java"><span class="token comment">/**
 * 发送微信小程序消息
 */</span>
<span class="token annotation punctuation">@Slf4j</span>
<span class="token annotation punctuation">@Service</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">RebateWxAppMsgStrategy</span> <span class="token keyword">extends</span> <span class="token class-name">AbstractRebateMsgStrategy</span> <span class="token punctuation">&#123;</span>

    <span class="token annotation punctuation">@Autowired</span>
    <span class="token keyword">private</span> <span class="token class-name">MsgCenterClient</span> msgCenterClient<span class="token punctuation">;</span>

    <span class="token comment">/**
     * 获取消息推送渠道
     */</span>
    <span class="token annotation punctuation">@Override</span>
    <span class="token keyword">protected</span> <span class="token class-name">MsgPushChannelEnum</span> <span class="token function">getMsgPushChannelEnum</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
        <span class="token keyword">return</span> <span class="token class-name">MsgPushChannelEnum</span><span class="token punctuation">.</span><span class="token constant">WX_APP</span><span class="token punctuation">;</span>
    <span class="token punctuation">&#125;</span>


    <span class="token comment">/**
     * 执行具体的消息发送策略
     * @param msgType
     * @param msgSendReqDto
     */</span>
    <span class="token annotation punctuation">@Override</span>
    <span class="token keyword">protected</span> <span class="token keyword">void</span> <span class="token function">doRebateMsgSend</span><span class="token punctuation">(</span><span class="token class-name">RebateMsgTypeEnum</span> msgType<span class="token punctuation">,</span> <span class="token class-name">MsgSendReqDto</span> msgSendReqDto<span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
        log<span class="token punctuation">.</span><span class="token function">info</span><span class="token punctuation">(</span><span class="token string">"[分润消息V2]发送微信小程序消息,msgType：&#123;&#125;,msgSendReqDto：&#123;&#125;"</span><span class="token punctuation">,</span> msgType<span class="token punctuation">.</span><span class="token function">name</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
                 <span class="token constant">JSON</span><span class="token punctuation">.</span><span class="token function">toJSONString</span><span class="token punctuation">(</span>msgSendReqDto<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

        <span class="token class-name">WxAppMsgContentDto</span> wxAppMsgContentDto
            <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token class-name">WxAppMsgContentDto</span><span class="token punctuation">)</span> msgSendReqDto<span class="token punctuation">.</span><span class="token function">getContentDto</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">MessageReq</span> req <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">MessageReq</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">MessageReq<span class="token punctuation">.</span>WeappTemplateMsgReq</span> weappTemplateMsgReq
            <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">MessageReq<span class="token punctuation">.</span>WeappTemplateMsgReq</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        weappTemplateMsgReq<span class="token punctuation">.</span><span class="token function">setTemplateId</span><span class="token punctuation">(</span>wxAppMsgContentDto<span class="token punctuation">.</span><span class="token function">getTemplateId</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
                <span class="token punctuation">.</span><span class="token function">setPage</span><span class="token punctuation">(</span>wxAppMsgContentDto<span class="token punctuation">.</span><span class="token function">getUrl</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
                <span class="token punctuation">.</span><span class="token function">setDataByMap</span><span class="token punctuation">(</span>wxAppMsgContentDto<span class="token punctuation">.</span><span class="token function">getParamMap</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        req<span class="token punctuation">.</span><span class="token function">setAppid</span><span class="token punctuation">(</span>wxAppMsgContentDto<span class="token punctuation">.</span><span class="token function">getAppId</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
                <span class="token punctuation">.</span><span class="token function">setMessageType</span><span class="token punctuation">(</span><span class="token class-name">MessageCenterTypeEnum</span><span class="token punctuation">.</span><span class="token constant">WECHAT_APP</span><span class="token punctuation">.</span><span class="token function">getType</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
                <span class="token punctuation">.</span><span class="token function">setToUser</span><span class="token punctuation">(</span>msgSendReqDto<span class="token punctuation">.</span><span class="token function">getTo</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
                <span class="token punctuation">.</span><span class="token function">setWeappTemplateMsg</span><span class="token punctuation">(</span>weappTemplateMsgReq<span class="token punctuation">)</span><span class="token punctuation">;</span>
        msgCenterClient<span class="token punctuation">.</span><span class="token function">sendMsg</span><span class="token punctuation">(</span><span class="token function">getMsgPushChannelEnum</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> req<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">&#125;</span>
<span class="token punctuation">&#125;</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre></div></figure></li>
</ol>

                
              </div>
            
            <hr/>
            <div>
              <div class="post-metas my-3">
  
    <div class="post-meta mr-3 d-flex align-items-center">
      <i class="iconfont icon-category"></i>
      

<span class="category-chains">
  
  
    
      <span class="category-chain">
        
  <a href="/categories/%E9%A1%B9%E7%9B%AE%E5%AE%9E%E6%88%98/" class="category-chain-item">项目实战</a>
  
  

      </span>
    
  
</span>

    </div>
  
  
    <div class="post-meta">
      <i class="iconfont icon-tags"></i>
      
        <a href="/tags/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F/" class="print-no-link">#设计模式</a>
      
        <a href="/tags/%E7%AD%96%E7%95%A5%E6%A8%A1%E5%BC%8F/" class="print-no-link">#策略模式</a>
      
        <a href="/tags/%E8%B4%A3%E4%BB%BB%E9%93%BE%E6%A8%A1%E5%BC%8F/" class="print-no-link">#责任链模式</a>
      
        <a href="/tags/%E6%B6%88%E6%81%AF%E5%8F%91%E9%80%81/" class="print-no-link">#消息发送</a>
      
    </div>
  
</div>


              
  

  <div class="license-box my-3">
    <div class="license-title">
      <div>项目实战：策略与责任链模式在项目中的应用</div>
      <div>http://example.com/2023/02/08/项目实战：策略与责任链模式在项目中的应用/</div>
    </div>
    <div class="license-meta">
      
        <div class="license-meta-item">
          <div>作者</div>
          <div>XiaoMaDing</div>
        </div>
      
      
        <div class="license-meta-item license-meta-date">
          <div>发布于</div>
          <div>2023年2月8日</div>
        </div>
      
      
      
        <div class="license-meta-item">
          <div>许可协议</div>
          <div>
            
              
              
                <a class="print-no-link" target="_blank" href="https://creativecommons.org/licenses/by/4.0/">
                  <span class="hint--top hint--rounded" aria-label="BY - 署名">
                    <i class="iconfont icon-by"></i>
                  </span>
                </a>
              
            
          </div>
        </div>
      
    </div>
    <div class="license-icon iconfont"></div>
  </div>



              
                <div class="post-prevnext my-3">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/2023/02/25/%E5%BC%82%E5%B8%B8%E5%AE%9A%E4%BD%8D%EF%BC%9A%E4%BD%BF%E7%94%A8MAT%E5%88%86%E6%9E%90OOM%E5%BC%82%E5%B8%B8/" title="异常定位：使用MAT分析OOM异常">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">异常定位：使用MAT分析OOM异常</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/2023/01/10/%E9%A1%B9%E7%9B%AE%E5%AE%9E%E6%88%98%EF%BC%9A%E8%B7%9D%E7%A6%BB%E7%94%A8%E6%88%B7%E6%9C%80%E8%BF%91%E7%9A%843%E4%B8%AA%E7%BD%91%E7%82%B9/" title="项目实战：距离用户最近的3个网点">
                        <span class="hidden-mobile">项目实战：距离用户最近的3个网点</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
  
  
    <article id="comments" lazyload>
      
  <div id="valine"></div>
  <script type="text/javascript">
    Fluid.utils.loadComments('#valine', function() {
      Fluid.utils.createScript('https://lib.baomitu.com/valine/1.5.1/Valine.min.js', function() {
        var options = Object.assign(
          {"appId":"fwhgdRnxBMBQuwXd6G2KY7uA-gzGzoHsz","appKey":"wz9qgHwvuMw8Y0yXAvL1KEr4","path":"window.location.pathname","placeholder":null,"avatar":"retro","meta":["nick","mail","link"],"requiredFields":[],"pageSize":10,"lang":"zh-CN","highlight":false,"recordIP":false,"serverURLs":"","emojiCDN":null,"emojiMaps":null,"enableQQ":false},
          {
            el: "#valine",
            path: window.location.pathname
          }
        )
        new Valine(options);
        Fluid.utils.waitElementVisible('#valine .vcontent', () => {
          var imgSelector = '#valine .vcontent img:not(.vemoji)';
          Fluid.plugins.imageCaption(imgSelector);
          Fluid.plugins.fancyBox(imgSelector);
        })
      });
    });
  </script>
  <noscript>Please enable JavaScript to view the comments</noscript>


    </article>
  


          </article>
        </div>
      </div>
    </div>

    <div class="side-col d-none d-lg-block col-lg-2">
      

    </div>
  </div>
</div>





  



  



  



  



  







    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v" for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>

    

    
  </main>

  <footer>
    <div class="footer-inner">
  
    <div class="footer-content">
       <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a> <i class="iconfont icon-love"></i> <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener"><span>Fluid</span></a> 
    </div>
  
  
    <div class="statistics">
  
  

  
    
      <span id="busuanzi_container_site_pv" style="display: none">
        总访问量 
        <span id="busuanzi_value_site_pv"></span>
         次
      </span>
    
    
      <span id="busuanzi_container_site_uv" style="display: none">
        总访客数 
        <span id="busuanzi_value_site_uv"></span>
         人
      </span>
    
    
  
</div>

  
  
  
</div>

  </footer>

  <!-- Scripts -->
  
  <script  src="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://lib.baomitu.com/jquery/3.6.0/jquery.min.js" ></script>
<script  src="https://lib.baomitu.com/twitter-bootstrap/4.6.1/js/bootstrap.min.js" ></script>
<script  src="/js/events.js" ></script>
<script  src="/js/plugins.js" ></script>


  <script  src="https://lib.baomitu.com/typed.js/2.0.12/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var subtitle = document.getElementById('subtitle');
      if (!subtitle || !typing) {
        return;
      }
      var text = subtitle.getAttribute('data-typed-text');
      
        typing(text);
      
    })(window, document);
  </script>




  
    <script  src="/js/img-lazyload.js" ></script>
  




  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/tocbot/4.18.2/tocbot.min.js', function() {
    var toc = jQuery('#toc');
    if (toc.length === 0 || !window.tocbot) { return; }
    var boardCtn = jQuery('#board-ctn');
    var boardTop = boardCtn.offset().top;

    window.tocbot.init(Object.assign({
      tocSelector     : '#toc-body',
      contentSelector : '.markdown-body',
      linkClass       : 'tocbot-link',
      activeLinkClass : 'tocbot-active-link',
      listClass       : 'tocbot-list',
      isCollapsedClass: 'tocbot-is-collapsed',
      collapsibleClass: 'tocbot-is-collapsible',
      scrollSmooth    : true,
      includeTitleTags: true,
      headingsOffset  : -boardTop,
    }, CONFIG.toc));
    if (toc.find('.toc-list-item').length > 0) {
      toc.css('visibility', 'visible');
    }

    Fluid.events.registerRefreshCallback(function() {
      if ('tocbot' in window) {
        tocbot.refresh();
        var toc = jQuery('#toc');
        if (toc.length === 0 || !tocbot) {
          return;
        }
        if (toc.find('.toc-list-item').length > 0) {
          toc.css('visibility', 'visible');
        }
      }
    });
  });
</script>


  <script  src="https://lib.baomitu.com/prism/1.29.0/plugins/line-numbers/prism-line-numbers.min.js" ></script>

  <script src=https://lib.baomitu.com/clipboard.js/2.0.11/clipboard.min.js></script>

  <script>Fluid.plugins.codeWidget();</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/anchor-js/4.3.1/anchor.min.js', function() {
    window.anchors.options = {
      placement: CONFIG.anchorjs.placement,
      visible  : CONFIG.anchorjs.visible
    };
    if (CONFIG.anchorjs.icon) {
      window.anchors.options.icon = CONFIG.anchorjs.icon;
    }
    var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
    var res = [];
    for (var item of el) {
      res.push('.markdown-body > ' + item.trim());
    }
    if (CONFIG.anchorjs.placement === 'left') {
      window.anchors.options.class = 'anchorjs-link-left';
    }
    window.anchors.add(res.join(', '));

    Fluid.events.registerRefreshCallback(function() {
      if ('anchors' in window) {
        anchors.removeAll();
        var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
        var res = [];
        for (var item of el) {
          res.push('.markdown-body > ' + item.trim());
        }
        if (CONFIG.anchorjs.placement === 'left') {
          anchors.options.class = 'anchorjs-link-left';
        }
        anchors.add(res.join(', '));
      }
    });
  });
</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.js', function() {
    Fluid.plugins.fancyBox();
  });
</script>


  <script>Fluid.plugins.imageCaption();</script>

  <script  src="/js/local-search.js" ></script>

  <script defer src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js" ></script>





<!-- 主题的启动项，将它保持在最底部 -->
<!-- the boot of the theme, keep it at the bottom -->
<script  src="/js/boot.js" ></script>


  

  <noscript>
    <div class="noscript-warning">博客在允许 JavaScript 运行的环境下浏览效果更佳</div>
  </noscript>
</body>
</html>
